package phoneBook;

import rme.RmeConfigurator;
import rme.naming.RmeNaming;
import arcademis.ArcademisException;
import arcademis.NotBoundException;
import arcademis.ReconfigurationException;
import arcademis.concreteComponents.MalformedURLException;

public class Client {

	public static void main(String args[]) throws ReconfigurationException {
		RmeConfigurator conf = new RmeConfigurator();
		conf.configure();

		if(args.length < 1) {
			System.err.println("Sintaxe: java Client objName");
			System.exit(1);
		}
		else {
			try {
				PhoneCatalogue p = (PhoneCatalogue)RmeNaming.lookup(args[0]);

				try{
					for(;;) {
						Thread.sleep(1000l);
						PhoneAddress a = p.getPhoneAddress("Fernando Magno");
						System.out.println(a.toString());
					}					
				} catch (ArcademisException e) {
					System.out.println(e.getMessage());
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			} catch (ArcademisException e) {
				e.printStackTrace();
			} catch (MalformedURLException e) {
				e.printStackTrace();
			} catch (NotBoundException e) {
				e.printStackTrace();
			}
		}
	}
}